package gov.pbc.nn.kjgl.train.view;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

import gov.pbc.nn.core.dao.PbcnnCoreJdbcDao;
import gov.pbc.nn.kjgl.entity.TrainingPlan;
import gov.pbc.nn.kjgl.train.dao.TrainRegisterDao;
import gov.pbc.nn.kjgl.train.dao.TrainRegisterJdbcDao;

@Component
public class TrainRegisterPR {

	@Autowired
	private TrainRegisterDao trainRegisterDao;
	
	@Autowired
	private TrainRegisterJdbcDao trainRegisterJdbcDao;
	
	@DataProvider
	public void getAll(Page<TrainingPlan> page,Criteria criteria) {
		trainRegisterJdbcDao.getAll(page,criteria);
	}
	
	
	@Transactional
	@Expose
	public void insertMeetingUser(Map<String, Object> parameter) {
		String id = (String) parameter.get("trainPlanId");
		List<String> username = (List<String>) parameter.get("username");
		List<String> cname = (List<String>) parameter.get("cname");
		List<String> ename = (List<String>) parameter.get("ename");
		TrainingPlan tp = trainRegisterDao.selectTrainPlanById(id);
		for (int i = 0; i < username.size(); i++) {
			Map<String, Object> param = new HashMap<String, Object>();
			param .put("deptId", trainRegisterJdbcDao.getDept(username.get(i)).get(0).get("deptId"));
			param .put("deptName", trainRegisterJdbcDao.getDept(username.get(i)).get(0).get("deptName"));
			param.put("username", username.get(i));
			param.put("cname", cname.get(i));
			param.put("ename", ename.get(i));
			trainRegisterDao.insertMeetingUser(tp, param);
		}
	}
	
	@Expose
	public boolean getTime(String id) {
		return trainRegisterDao.getTime(id);
	}

}
